﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZoneLine.Models;
using ZoneLine.Models.XWStations;

namespace ZoneLine.Stations.XWStation
{
    public class XW010LStation : XWStationBase
    {

        public XW010LStation()
        {
            _logUiChannel = nameof(HOP010Station) + "uilog";
        }

        protected override int RecordData()
        {
            var result = new XW010LStationResult()
            {
                AbsScanCode = StationRecordData.AbsScanCode,
                BushScanCode = StationRecordData.BushScanCode,
                StationCode = this.StationCode,
                PartType = StationRecordData.PartType,
                Result = StationRecordData.Result,
                PressPosition = StationRecordData.PressPosition,
                PressForce = StationRecordData.PressForce,
                CycleTime = StationRecordData.CycleTime,
            };
            var writeRlt = false;
            if (_dal.CheckExist<XW010LStationResult>(p => p.AbsScanCode == result.AbsScanCode))
            {
                var beforeRlt = _dal.GetModel<XW010LStationResult>(p => p.AbsScanCode == result.AbsScanCode);
                result.Id = beforeRlt.Id;
                writeRlt = _dal.UpdateModelSuper<XW010LStationResult>(p => p.AbsScanCode == result.AbsScanCode, result);
            }
            else
            {
                writeRlt = _dal.AddModel(result);

            }
            return writeRlt ? 1 : 2;
        }
    }
}
